﻿Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class CodeEditor
#Region "属性"
    ReadOnly Property InputMode() As EnumInputMode
        Get
            Return CodeBox.mInputMode
        End Get
    End Property
    ReadOnly Property InputPosition() As Point
        Get
            Return ExDocument.InputPosition
        End Get
    End Property
    ReadOnly Property CharPosition() As Integer
        Get
            Return ExDocument.CharPosition
        End Get
    End Property
    <Description("单行程序最大允许的字符数，例如PL1和COBOL的时候，最大允许80个字符"), Category("源代码")> _
    Public Property SingleLineMinLength() As Byte
        Get
            Return mSingleLineMinLength
        End Get
        Set(ByVal value As Byte)
            mSingleLineMinLength = value
        End Set
    End Property
    <Description("单行程序最大允许的字符数，例如PL1和COBOL的时候，最大允许80个字符"), Category("源代码")> _
   Public Property SingleLineMaxLength() As Byte
        Get
            Return mSingleLineMaxLength
        End Get
        Set(ByVal value As Byte)
            mSingleLineMaxLength = value
        End Set
    End Property
    <Description("选中背景色"), Category("源代码")> _
    Property SelectionBackColor() As Color
        Get
            Return ExSelectionBackColor
        End Get
        Set(ByVal value As Color)
            ExSelectionBackColor = value
            Me.Refresh()
        End Set
    End Property
    <Description("选中文字色"), Category("源代码")> _
    Property SelectionForeColor() As Color
        Get
            Return ExSelectionForeColor
        End Get
        Set(ByVal value As Color)
            ExSelectionForeColor = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 字体
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("字体"), Category("源代码")> _
    Property CodeFont() As Font
        Get
            If ExFont Is Nothing Then
                Return Me.Font
            Else
                Return ExFont
            End If
        End Get
        Set(ByVal value As Font)
            ExFont = value
            CodeBox.SetCodeFont(value)
            ExDocument.ReSetWidth()
            ExDocument.ResetMaxLineWidth()
            '如果最大宽度小于或等于窗体宽度，则初始化滚动条
            HScrollBarEx.Maximum = 1
            HScrollBarEx.Value = 1
            Me.HScrollBarEx.ChangeScroll()
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 字体颜色
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("字体颜色"), Category("源代码")> _
     Property CodeForeColor() As Color
        Get
            Return ExForeColor
        End Get
        Set(ByVal value As Color)
            ExForeColor = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 注释颜色
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("注释颜色"), Category("源代码")> _
    Property CommentColor() As Color
        Get
            Return ExCommentColor
        End Get
        Set(ByVal value As Color)
            ExCommentColor = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 引用字符的颜色
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("引用字符的颜色"), Category("源代码")> _
    Property QuateColor() As Color
        Get
            Return ExQuateColor
        End Get
        Set(ByVal value As Color)
            ExQuateColor = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 单个Tab置换为半角空格数量，0的时候则不置换
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("单个Tab置换多少半角空格"), Category("源代码")> _
    Public Property SpaceForTab() As Byte
        Get
            Return TabSpace
        End Get
        Set(ByVal value As Byte)
            TabSpace = value
        End Set
    End Property
    ''' <summary>
    ''' 控件背景色
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("背景颜色"), Category("源代码")> _
     Property CodeBackColor() As Color
        Get
            Return ExBackColor
        End Get
        Set(ByVal value As Color)
            ExBackColor = value
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 当控件失去焦点时的背景色
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Description("失去焦点背景色"), Category("源代码")> _
    Property RulerColor() As Color
        Get
            Return ExRulerColor
        End Get
        Set(ByVal value As Color)
            ExRulerColor = value
        End Set
    End Property
    ''' <summary>
    ''' 对ToolTip字典进行填充
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False)> _
    Property ToolTipTable() As Dictionary(Of String, String)
        Get
            Return tblToolTip
        End Get
        Set(ByVal value As Dictionary(Of String, String))
            tblToolTip = value
        End Set
    End Property
    ''' <summary>
    ''' 对智能完成字典进行填充
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False)> _
    Property WordList() As Dictionary(Of String, String)
        Get
            Return AutoFillWordList
        End Get
        Set(ByVal value As Dictionary(Of String, String))
            AutoFillWordList = value
        End Set
    End Property
    ''' <summary>
    ''' 对上色字典进行填充
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False)> _
    Property ColorTable() As Dictionary(Of String, Color)
        Get
            Return ColorfulWord
        End Get
        Set(ByVal value As Dictionary(Of String, Color))
            ColorfulWord = value
        End Set
    End Property
    ''' <summary>
    ''' 设置单行注释的标志
    ''' </summary>
    ''' <remarks></remarks>
    Property SingleComment() As String
        Get
            Return SingleCommentMark
        End Get
        Set(ByVal value As String)
            SingleCommentMark = value
        End Set
    End Property
    ''' <summary>
    ''' 设置块注释的开始标志
    ''' </summary>
    ''' <remarks></remarks>
    Property CommentStart() As String
        Get
            Return BlockCommentStartMark
        End Get
        Set(ByVal value As String)
            BlockCommentStartMark = value
            ExDocument.ResetComment()
        End Set
    End Property
    ''' <summary>
    ''' 设置块注释的结束标志
    ''' </summary>
    ''' <remarks></remarks>
    Property CommentEnd() As String
        Get
            Return BlockCommentEndMark
        End Get
        Set(ByVal value As String)
            BlockCommentEndMark = value
            ExDocument.ResetComment()
        End Set
    End Property
    ''' <summary>
    ''' 设置分割单词标志
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False)> _
    Property DelimitChar() As List(Of String)
        Get
            Return DelimitMark
        End Get
        Set(ByVal value As List(Of String))
            DelimitMark = value
            For i As Integer = 1 To ExDocument.MaxMemoryLineNumber
                ExDocument.GetMemoryLine(i).RefreshWordList()
            Next
            Me.Refresh()
        End Set
    End Property
    ''' <summary>
    ''' 获得主文档
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Browsable(False)> _
    ReadOnly Property MainDocument() As Document
        Get
            Return ExDocument
        End Get
    End Property
    ''' <summary>
    ''' 列模式
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Browsable(False)> _
    ReadOnly Property ColumnMode() As Boolean
        Get
            Return ExColumnMode
        End Get
    End Property
    ''' <summary>
    ''' 折行显示
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Browsable(False)> _
    ReadOnly Property WordWrapMode() As Boolean
        Get
            Return ExWordWrapMode
        End Get
    End Property
    ''' <summary>
    ''' 箱型选择
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Browsable(False)> _
    ReadOnly Property BoxSelectMode() As Boolean
        Get
            Return ExBoxSelectMode
        End Get
    End Property
    ''' <summary>
    ''' 只读
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Browsable(False)> _
    ReadOnly Property ReadOnlyMode() As Boolean
        Get
            Return ExReadOnlyMode
        End Get
    End Property
#End Region
#Region "方法"
    ''' <summary>
    ''' 构造器
    ''' </summary>
    ''' <remarks></remarks>
    Sub New()
        ' 此调用是 Windows 窗体设计器所必需的。
        ShareG = Me.CreateGraphics
        InitializeComponent()
        ExFont = Me.Font
        ' 在 InitializeComponent() 调用之后添加任何初始化。
        AddHandler CodeBox.ChangeVScroll, AddressOf CodeLineNumber.Refresh
        AddHandler CodeBox.ChangeVScroll, AddressOf VScrollBarEx.ChangeScroll
        AddHandler CodeBox.ChangeHScroll, AddressOf HScrollBarEx.ChangeScroll
        AddHandler CodeBox.ColumnModeStart, AddressOf CodeLineNumber.SetColumnModeStart
        AddHandler CodeBox.ColumnModeEnd, AddressOf CodeLineNumber.SetColumnModeEnd
        AddHandler CodeBox.ClearColumn, AddressOf CodeLineNumber.ClearColumnMode
        AddHandler ExDocument.StepList.UnReDoChanged, AddressOf RaisedUnRedoChanged
        '默认的分割单词方法
        Dim DelimitChar As New List(Of String)
        DelimitChar.Add("(")
        DelimitChar.Add(")")
        DelimitChar.Add("<")
        DelimitChar.Add(">")
        DelimitChar.Add(",")
        DelimitChar.Add(".")
        DelimitChar.Add(";")
        DelimitChar.Add(Chr(34))
        Me.DelimitChar = DelimitChar
        '列模式
        ExColumnMode = False
    End Sub
    ''' <summary>
    ''' 设置语法规则
    ''' </summary>
    ''' <param name="value"></param>
    ''' <remarks></remarks>
    Sub SetSytaxKeyList(ByVal value As List(Of SyntaxKey))
        ExSyntaxKeyList = value
    End Sub
    ''' <summary>
    ''' 垂直滚动条事件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub VScrollBarEx_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBarEx.ValueChanged
        CodeLineNumber.Refresh()
        '如果这个事件本来就是TextBoxEx引发的,不需要再次传回TextBoxEx,造成效率的下降
        If VScrollBarEx.IsInfoToChange Then Exit Sub
        FirstVisiableLineNumber = VScrollBarEx.Value
        CodeBox.FirstLineChanged()
    End Sub
    ''' <summary>
    ''' 水平滚动条事件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub HScrollBarEx_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBarEx.ValueChanged
        Dim OffsetWidth As Integer
        OffsetWidth = (HScrollBarEx.Value - 1)
        CodeBox.SetWidthOffset(OffsetWidth)
    End Sub
    ''' <summary>
    ''' 引发插入点改变事件
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub NotifyPos() Handles CodeBox.InputPositionChanged
        Me.CodeLineNumber.Refresh()
        RaiseEvent PositionChanged(ExDocument.InputPosition, ExDocument.CharPosition)
    End Sub
    ''' <summary>
    ''' 引发编辑模式改变事件
    ''' </summary>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ChangeInputMode(ByVal e As EnumInputMode) Handles CodeBox.InputModeChanged
        RaiseEvent InputModeChanged(e)
    End Sub
    ''' <summary>
    ''' 用行号栏来选中整行
    ''' </summary>
    ''' <param name="StartLineNumber"></param>
    ''' <param name="EndLineNumber"></param>
    ''' <param name="FirstLine"></param>
    ''' <remarks></remarks>
    Private Sub SelectLineByLineNumber(ByVal StartLineNumber As Integer, ByVal EndLineNumber As Integer, ByVal FirstLine As Integer) Handles CodeLineNumber.SelectTextByLineNumber
        CodeBox.SelectWholeLines(StartLineNumber, EndLineNumber, FirstLine)
    End Sub
    Private Sub FontChange(ByVal NewFont As Font) Handles CodeBox.FontChange
        CodeFont = NewFont
    End Sub
    ''' <summary>
    ''' 展开或者折叠代码
    ''' </summary>
    ''' <param name="DisplayLineNo"></param>
    ''' <remarks></remarks>
    Sub SwitchFolder(ByVal DisplayLineNo As Integer) Handles CodeLineNumber.LineClicked
        '检查这个行是否可以展开或者折叠
        With ExDocument.GetMemoryLineByDisplayLineNumber(DisplayLineNo)
            If .Real_IsBlockHeader Then
                If .Real_IsFolder Then
                    ExDocument.Expend(DisplayLineNo)
                Else
                    ExDocument.Folder(DisplayLineNo)
                End If
                Me.Refresh()
            End If
        End With
    End Sub
    Sub ToggleBookMarkByLineNumber(ByVal DisplayLineNo As Integer) Handles CodeLineNumber.LineDoubleClicked
        Dim RealLineNumber As Integer = ExDocument.GetMemoryLineByDisplayLineNumber(DisplayLineNo).Dis_RealLineNumber
        If ExDocument.lstBookMark.Contains(RealLineNumber) Then
            ExDocument.DeleteBookMark(RealLineNumber)
        Else
            ExDocument.AddBookMark(RealLineNumber)
        End If
        CodeLineNumber.Refresh()
        RaiseEvent BookMarkChanged(ExDocument.lstBookMark.Count > 0)
    End Sub
    ''' <summary>
    ''' 文件拖曳
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <remarks>将内部事件转换为外部事件</remarks>
    Sub RaiseDropFile(ByVal FileName As String) Handles CodeBox.DropFile
        RaiseEvent DropFile(FileName)
    End Sub
    ''' <summary>
    ''' 关键字没有找到
    ''' </summary>
    ''' <remarks>将内部事件转换为外部事件</remarks>
    Sub RaiseWordNotFound() Handles CodeBox.WordNotFound
        RaiseEvent WordNotFound()
    End Sub
    ''' <summary>
    ''' 重做折行显示
    ''' </summary>
    ''' <remarks></remarks>
    Sub ReWordWrap() Handles CodeBox.ReWordWrap
        ExDocument.UnDoWrapWord()
        ExDocument.DoWrapWord()
    End Sub
    ''' <summary>
    ''' 可以撤销或者重做发生变化
    ''' </summary>
    ''' <remarks></remarks>
    Sub RaisedUnRedoChanged()
        RaiseEvent UnRedoChanged()
    End Sub
#End Region
#Region "事件"
    ''' <summary>
    ''' 行列位置变更
    ''' </summary>
    ''' <param name="pos"></param>
    ''' <remarks></remarks>
    Public Event PositionChanged(ByVal pos As Point, ByVal ch As Integer)
    ''' <summary>
    ''' 输入模式变更
    ''' </summary>
    ''' <param name="Input_Mode"></param>
    ''' <remarks></remarks>
    Public Event InputModeChanged(ByVal Input_Mode As EnumInputMode)
    ''' <summary>
    ''' 文件拖曳
    ''' </summary>
    ''' <param name="FirstFileName"></param>
    ''' <remarks></remarks>
    Public Event DropFile(ByVal FirstFileName As String)
    ''' <summary>
    ''' 查找失败
    ''' </summary>
    ''' <remarks></remarks>
    Public Event WordNotFound()
    ''' <summary>
    ''' 撤销可能发生变更
    ''' </summary>
    ''' <remarks></remarks>
    Public Event UnRedoChanged()
    ''' <summary>
    ''' 撤销可能发生变更
    ''' </summary>
    ''' <remarks></remarks>
    Public Event BookMarkChanged(ByVal HasBookMark As Boolean)
#End Region
#Region "对外方法"
    ''' <summary>
    ''' 新文件
    ''' </summary>
    ''' <param name="mEncoding"></param>
    ''' <remarks></remarks>
    Public Sub NewFile(ByVal mEncoding As Encoding)
        CodeBox.ResetAll()
        ExDocument = New Document(mEncoding)
        AfterFileOperation()
    End Sub
    ''' <summary>
    ''' 加载文件
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <param name="mEncoding"></param>
    ''' <remarks></remarks>
    Public Sub LoadFile(ByVal FileName As String, ByVal mEncoding As Encoding)
        CodeBox.ResetAll()
        ExDocument.LoadFile(FileName, mEncoding)
        AfterFileOperation()
    End Sub
    ''' <summary>
    ''' 文件操作后处理
    ''' </summary>
    ''' <remarks></remarks>
    Sub AfterFileOperation()
        ExDocument.ResetMaxLineWidth()
        If ExDocument.MaxRealLineNumber > 1 Then ExDocument.SetAllSyntax()
        RaiseEvent PositionChanged(ExDocument.InputPosition, ExDocument.CharPosition)
        RaiseEvent InputModeChanged(EnumInputMode.InsertChar)
        Me.VScrollBarEx.ChangeScroll()
        Me.HScrollBarEx.ChangeScroll()
        ExColumnMode = False
        ExWordWrapMode = False
        ExReadOnlyMode = False
        ExDocument.ClearBookMarks()
        Me.CodeLineNumber.ClearColumnMode()
        ExDocument.ColumnModeList.Clear()
        ExDocument.StepList.Clear()
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 保存文件
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <param name="mEncoding"></param>
    ''' <remarks></remarks>
    Public Sub SaveFile(ByVal FileName As String, ByVal mEncoding As Encoding)
        ExDocument.SaveFile(FileName, mEncoding)
        ExDocument.StepList.Clear()
    End Sub
    ''' <summary>
    ''' 剪切
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Cut()
        If Not ReadOnlyMode Then
            CodeBox.Cut()
            Me.Refresh()
        End If
    End Sub
    ''' <summary>
    ''' 复制
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Copy()
        CodeBox.Copy()
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 粘贴
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Paste()
        If Not ReadOnlyMode Then
            CodeBox.Paste()
            Me.Refresh()
        End If
    End Sub
    ''' <summary>
    ''' 删除
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Delete()
        If Not ReadOnlyMode Then
            CodeBox.Delete()
            Me.Refresh()
        End If
    End Sub
    ''' <summary>
    ''' 全选
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectAll()
        ExDocument.UpdateSelection(New Point(1, 1), New Point(ExDocument.GetRealLineText(ExDocument.MaxRealLineNumber).Length + 1, ExDocument.MaxRealLineNumber))
        CodeBox.Refresh()
    End Sub
    ''' <summary>
    ''' 撤销
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub UnDo()
        If ReadOnlyMode Then Exit Sub
        CodeBox.Undo()
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 重做
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Redo()
        If ReadOnlyMode Then Exit Sub
        CodeBox.Redo()
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 插入任意文字
    ''' </summary>
    ''' <param name="strWord"></param>
    ''' <remarks></remarks>
    Public Sub InsertString(ByVal strWord As String)
        If ReadOnlyMode Then Exit Sub
        If ExColumnMode Then
            If Not ExDocument.FirstColumnLine = 0 Then
                ExDocument.InsertString(strWord)
            End If
        Else
            ExDocument.InsertSelection(strWord)
        End If
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 查找
    ''' </summary>
    ''' <param name="strFind">关键字</param>
    ''' <remarks></remarks>
    Public Sub SetSearchWord(ByVal strFind As String)
        Me.CodeBox.SearchWord = strFind
    End Sub
    ''' <summary>
    ''' 查找下一个
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub FindNext()
        CodeBox.FindNext()
    End Sub
    ''' <summary>
    ''' 查找上一个
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub FindPrevious()
        CodeBox.FindPrevious()
    End Sub
    ''' <summary>
    ''' 替换
    ''' </summary>
    ''' <param name="strReplace"></param>
    ''' <remarks></remarks>
    Public Sub Replace(ByVal strReplace As String)
        If ReadOnlyMode Then Exit Sub
        CodeBox.Replace(strReplace)
    End Sub
    ''' <summary>
    ''' 替换所有
    ''' </summary>
    ''' <param name="strOld"></param>
    ''' <param name="strNew"></param>
    ''' <remarks></remarks>
    Public Sub ReplaceALL(ByVal strOld As String, ByVal strNew As String)
        If ReadOnlyMode Then Exit Sub
        CodeBox.ReplaceAll(strOld, strNew)
    End Sub
    ''' <summary>
    ''' 设置高亮关键字
    ''' </summary>
    ''' <param name="strWord"></param>
    ''' <remarks></remarks>
    Public Sub SetHeightLightWord(ByVal strWord As String)
        Me.CodeBox.HeightLightWord = strWord
    End Sub
    ''' <summary>
    ''' 跳转到指定行
    ''' </summary>
    ''' <param name="LineNumber"></param>
    ''' <remarks></remarks>
    Public Sub JumpTo(ByVal LineNumber As Integer, ByVal VP As VPosition)
        CodeBox.JumpToLine(LineNumber, VP)
    End Sub
    ''' <summary>
    ''' 列模式切换
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SwitchColumnMode()
        ExColumnMode = Not ExColumnMode
        If Not ExColumnMode Then
            Me.CodeLineNumber.ClearColumnMode()
            ExDocument.ColumnModeList.Clear()
            CodeBox.Refresh()
        End If
    End Sub
    ''' <summary>
    ''' 切换折行显示
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SwitchWordWrap()
        ExWordWrapMode = Not ExWordWrapMode
        If ExWordWrapMode Then
            ExDocument.DoWrapWord(Me.CodeBox.Width)
            Me.HScrollBarEx.Init()
            If ExColumnMode Then
                ExColumnMode = False
                Me.CodeLineNumber.ClearColumnMode()
                ExDocument.ColumnModeList.Clear()
            End If
        Else
            ExDocument.UnDoWrapWord()
            Me.HScrollBarEx.ChangeScroll()
        End If
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 箱型选择模式切换
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SwitchBoxSelectMode()
        ExBoxSelectMode = Not ExBoxSelectMode
    End Sub
    ''' <summary>
    ''' 切换只读模式
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SwitchReadOnly()
        ExReadOnlyMode = Not ExReadOnlyMode
    End Sub
    ''' <summary>
    ''' 进行代码折叠
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetSytax()
        If ExDocument.MaxRealLineNumber > 1 Then ExDocument.SetAllSyntax()
    End Sub
    ''' <summary>
    ''' 清除所有书签
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ClearBookMark()
        ExDocument.ClearBookMarks()
        CodeLineNumber.Refresh()
    End Sub
    ''' <summary>
    ''' 上一个书签
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub PreviousBookMark()
        If ExDocument.lstBookMark.Count = 0 Then Exit Sub
        ExDocument.PreviousBookMark()
        CodeBox.JumpToLine(ExDocument.lstBookMark(ExDocument.BookMarkPosition - 1), VPosition.Middle)
    End Sub
    ''' <summary>
    ''' 下一个书签
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub NextBookMark()
        If ExDocument.lstBookMark.Count = 0 Then Exit Sub
        ExDocument.NextBookMark()
        CodeBox.JumpToLine(ExDocument.lstBookMark(ExDocument.BookMarkPosition - 1), VPosition.Middle)
    End Sub
    ''' <summary>
    ''' 标记(撤销)书签
    ''' </summary>
    ''' <remarks></remarks>
    Function SwitchBookMark() As Boolean
        If ExDocument.lstBookMark.Contains(ExDocument.InputPosition.Y) Then
            ExDocument.DeleteBookMark(ExDocument.InputPosition.Y)
        Else
            ExDocument.AddBookMark(ExDocument.InputPosition.Y)
        End If
        CodeLineNumber.Refresh()
        If ExDocument.lstBookMark.Count > 0 Then Return True
    End Function
    ''' <summary>
    ''' 收缩所有代码
    ''' </summary>
    ''' <remarks></remarks>
    Sub CollapseALL()
        ExDocument.CollapseALL()
        Me.Refresh()
        JumpTo(1, VPosition.Top)
    End Sub
    ''' <summary>
    ''' 展开所有代码
    ''' </summary>
    ''' <remarks></remarks>
    Sub ExpandAll()
        ExDocument.ExpandAll()
        Me.Refresh()
        JumpTo(1, VPosition.Top)
    End Sub
#End Region
End Class
